import java.io.*;
import java.net.*;

class shutdownCloud
{
 	public static void main(String args[]) throws Exception
 	{
		int pid=5000;
		if(args.length>0) {
			try {
				pid = Integer.parseInt(args[0]);
			} catch (NumberFormatException e) {
				System.err.println("Argument" + " must be an integer");
				System.exit(1);
			}
		}

		try {
			Socket clientSocket = new Socket("localhost", pid);
		  	String answer;

		  	ObjectOutputStream outToServer = new ObjectOutputStream(clientSocket.getOutputStream());
		  	ObjectInputStream inFromServer = new ObjectInputStream(clientSocket.getInputStream());

		  	outToServer.writeObject(new String("Shutdown"));
		  	answer = (String) inFromServer.readObject();
		  	System.out.println(answer);
		  	clientSocket.close();
		} catch (ConnectException e) {
	        	System.err.println("pid" + " must refer to a valid socket");
	        	System.exit(1);
		}				

 	}
}